#include <OsgClassDataSource/GroupOsg.h>
#include <Osg/Group>
#include <iostream>
#include <OBBboxVisitor.h>
GroupOsg::GroupOsg( QObject *parent /*= 0*/ ) : NodeOsg(parent)
{
    m_object = new osg::Group;
    this->refreshInfoContainer();

    m_OBBDisplay = false;
    m_obbNode = NULL;
}


GroupOsg::~GroupOsg()
{

}

EObject *GroupOsg::clone()
{
    NodeOsg* newObj = new GroupOsg();
    newObj->copyFrom(this);
    return newObj;

}

bool GroupOsg::getOBBDisplay()
{
    return m_OBBDisplay;
}

void GroupOsg::setOBBDisplay(bool boolValue)
{
    m_OBBDisplay = boolValue;
    if(boolValue)
    {
        osg::Group* groupPtr = dynamic_cast<osg::Group*>(m_object.get());
        if(groupPtr != NULL)
        {
            //std::cout<<"GroupOsg::setOBBDisplay"<<std::endl;
            OBBboxVisitor visitor;
            groupPtr->accept(visitor);
            m_obbNode = visitor.getBoxMT();
            groupPtr->addChild(m_obbNode);
        }
    }
    else
    {
        osg::Group* groupPtr = dynamic_cast<osg::Group*>(m_object.get());
        if(groupPtr != NULL)
        {
            groupPtr->removeChild(m_obbNode);
        }
    }
}

//OsgObjectQt *GroupOsg::clone()
//{
//    OsgObjectQt* new_object_qt = new GroupOsg(*this);

//        osg::CopyOp copy_op(osg::CopyOp::Options::DEEP_COPY_ALL);
//        osg::ref_ptr<osg::Object> new_node = copy_op(this->m_object);

//        new_object_qt->replaceOsgObject(new_node);
//        return new_object_qt;
//}

